package com.huaxiafinance.management.controller;

import com.huaxiafinance.management.dto.request.BonusDto;
import com.huaxiafinance.management.service.BonusService;
import com.huaxiafinance.management.util.MessageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;


@Controller("bonusController")
@RequestMapping("/bonus")
public class BonusController {

  protected Logger logger = Logger.getLogger(BonusController.class);
  @Autowired
  private BonusService bonusService;

  /**
   * 查询资金变动原因列表
   */
  @RequestMapping(value = "/queryBonusTypeList", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String queryBonusTypeList() {
    MessageResult messageResult = new MessageResult();
    try {
      messageResult = bonusService.queryBonusTypeList();
    } catch (Exception e) {
      messageResult.setFailureResult();
      logger.info("查询资金变动原因列表异常原因：" + e);
    }
    logger.info("查询资金变动原因列表返回参数：" + messageResult.getAsJSON());
    return messageResult.getAsJSON();
  }

  /**
   * 查询合伙人资金变动列表
   */
  @RequestMapping(value = "/queryBonusList", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String queryScoreGiftList(@Valid @RequestBody BonusDto dto, BindingResult bindingResult) {
    logger.info("查询合伙人资金变动列表参数：" + dto.toString());
    MessageResult messageResult = new MessageResult();
    if (bindingResult.hasErrors()) {
      messageResult.setFailureResult(bindingResult);
    } else {
      try {
        messageResult = bonusService.queryBonusList(dto);
      } catch (Exception e) {
        messageResult.setFailureResult();
        logger.info("查询合伙人资金变动列表异常原因：" + e);
      }
    }
    logger.info("查询合伙人资金变动列表返回参数：" + messageResult.getAsJSON());
    return messageResult.getAsJSON();
  }


}
